<template>
  <div>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="date" label="Id" width="200"> </el-table-column>
      <el-table-column prop="name" label="姓名" width="200"> </el-table-column>
      <el-table-column label="日期" v-slot:default={row}>
        {{new Date(row.address).toLocaleString()}} 
        </el-table-column>
      <el-table-column prop="ip" label="Ip"></el-table-column>
    </el-table>
  </div>
</template>

<script>
import logs from '@/api/logs'

export default {
  name: 'LogL',
  data() {
    return {
      tableData: []
    }
  },
  methods: {
    // 获取登录日志
    getLogs() {
      logs.getLog(this.$store.state.token).then((res) => {
        console.log(res)
        if (res.data.status == 'success') {
          let arr = []
          res.data.data.forEach((item) => {
            let obj = {
              date: item.id,
              name: item.username,
              address: item.create_time,
              ip: item.ip
            }
            arr.push(obj)
          })
          this.tableData = arr
        }
      })
    }
  },
  // 首次渲染
  mounted(){
    this.getLogs()
  }
}
</script>

<style>
</style>